<?php

include_once("db_object.php");
include_once("root_object.php");

class category_tree 
{

	function __construct()
	{
	}

	function print_tree()
	{
		
	}
}

class category extends root_object
{
	public $id;
	public $name;
	private $subcategory_list;
	private $product_list;
	public $parent_id;

	function __construct()
	{
		parent::__construct();
	}
	//-----------------------------------------------------------------------
	function __destruct()
	{
		parent::__destruct();
	}
	//-----------------------------------------------------------------------
	function load()
	{
		$this->load_product_list();
	}
	//-----------------------------------------------------------------------
	function save()
	{
		if( $this->id)
			$sql_str = "UPDATE category (name='" . $this->name . "',"
				."parent_id='" . $this->parent_id . "')"
				."WHERE category_id = '" . $this->id . "';";
		else
			$sql_str = "INSERT INTO category (name, parent_id) "
				."VALUES ('" . $this->name . "', '". $this->parent_id . "');";

		$this->DBObj->request($sql_str);
	}
	//-----------------------------------------------------------------------
	function erase()
	{
		
	}
	//-----------------------------------------------------------------------
	function load_product_list()
	{
		$result = $this->DBObj->request("SELECT product_id FROM 'product_category' WHERE 'category_id' = '" . $thid->id . "'");

		while( $array = pg_fetch_array($result))
		{
			$curr_product = New product( $array['product_id']);
			$this->product_list = $curr_product;
		}

	}
	//-----------------------------------------------------------------------

}

?>
